package org.software.views.group;

import org.software.controller.GroupController;
import javax.swing.*;
import java.awt.*;

public class GroupUpdateFrame extends JFrame {
    public GroupUpdateFrame(String groupName) {
        setTitle("修改班级");
        setSize(300, 200);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        JPanel panel = new JPanel();
        JPanel textPanel = new JPanel();
        JPanel buttonPanel = new JPanel();
        JLabel label = new JLabel("请输入小组名称：");
        JTextField textField = new JTextField(15);
        JButton positiveButton = new JButton("确认");
        JButton negativeButton = new JButton("取消");
        positiveButton.addActionListener(e -> {
            GroupController GroupController = new GroupController();
            if (GroupController.groupUpdate(groupName, textField.getText())) {
                JOptionPane.showMessageDialog(null, "修改成功");
                new GroupListFrame();
                dispose();
            } else {
                JOptionPane.showMessageDialog(null, "修改失败");
            }
        });
        negativeButton.addActionListener(e -> {
            new GroupListFrame();
        });
        textPanel.add(label);
        textPanel.add(textField);
        buttonPanel.add(positiveButton);
        buttonPanel.add(negativeButton);
        panel.add(textPanel);
        buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
        panel.add(buttonPanel);
        panel.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
        add(panel);
        setVisible(true);
    }
}